<template>
	<div>
		<m-pay :money="totalMoney" 
			:payClick="payClick" 
			:payCancel="payCancel"
			:goBack="goBack" 
			:walletMoney="walletMoney" 
			:walletBalance="walletBalance" 
			:thirdPayMoney="thirdPayMoney" 
			@changeWalletMoney="changeWalletMoneyEvent" 
			:orderType="orderType"
			:orderNo="orderNo"
			:autoCancelTime="autoCancelTm"
			:fullWalletPay="fullWalletPay">
		</m-pay>
		<passward-panel ref="passwardPanel" @passwordPendingChange="passwordPendingChangeEvent">
		</passward-panel>
	</div>
</template>

<script>
	import Pay from "../../real-components/Pay";
	import * as way from "../../config/pay-way"
	import { mapGetters } from "vuex";
	import getOrderInfo from "../../api/gw/getOrderInfo";
	import { getWalletBalance, walletPay } from "./axios";
	import { showLoading, hideLoading } from "../../utils/loading.js";
	import ValidatorFn from "../../utils/ValidatorFn"; //校验axios返回的数据是否合法
	import axios from "axios";
	import * as api from "../../api/gw/index.js";
	import md5 from "js-md5";
	import { Toast } from "../../utils/toast";
	import passwardPanel from "../../real-components/ConfirmOrder/ConfirmOrderPursekey"; //钱包支付密码面板
	import * as orderTypeCode from "../../config/orderTypeCode";
	export default {
		props: {},
		data() {
			return {
				orderMoney: 0, //调翌支付的金额
				payClick: () => {},
				payParams: null, //翌支付相关的参数,
				totalMoney: 0, //所有金额
				walletMoney: 0, //钱包金额
				walletMoneyState: false,
				walletBalance: 0, //钱包余额,
				thirdPayMoney: 0, //第三方支付（翌支付）的金额,
				pwPendingResult: {
					pwPendingState: true, //默认为true，代表在等待
					result: "initial",
					msg: ""
				}, //等待密码校验的对象
				isPaying: false, //是否正在支付中
				showPayForOthersBtn: true, //是否显示代付按钮
				autoCancelTm: 1, //过期时间
				fullWalletPay: false,
			}
		},
		computed: {
			...mapGetters("gw", [
				"getPayWay"
			]),
			...mapGetters("wxh", [
				"userInfo"
			]),
			...mapGetters([
				"payS"
			]),
			orderNo() {
				this.$route.params.orderNo && localStorage.setItem("orderNo", this.$route.params.orderNo);
				return this.$route.params.orderNo || localStorage.getItem("orderNo");
			},
			//订单类型，线上订单为2（跳转到待配送），线下订单为1（跳转到全部）,礼品卡为12
			orderType() {
				// this.$route.params.orderType && localStorage.setItem("orderType", this.$route.params.orderType);
				// return this.$route.params.orderType || Number(localStorage.getItem("orderType"));
				return this.$route.params.orderType
			},
			//获取设备类型
			phoneType() {
				let u = navigator.userAgent;
				let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android
				let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios
				return isAndroid ? "Android" : "iOS";
			},
			//判断是否在象谱内
			isXiangpu() {
				return navigator.userAgent.indexOf("xiangpu") > -1;
			},
			//钱包支付选中状态
			walletChoosed() {
				return this.getPayWay.join(",").indexOf(way.wallet) > -1;
			},
			//翌支付选中状态
			yizhifuChoosed() {
				return this.getPayWay.join(",").indexOf(way.yizhifu) > -1;
			},
			//获取会员免密金额
			moneyWithoutCode() {
				return this.userInfo.moneyWithoutCode;
			}
		},
		methods: {
			goBack() {
				// 跳转到待支付页面
				if(this.orderType === orderTypeCode.lipinquan) {
					this.$router.replace({
						name: "GiftOrderDetails",
						query: {
							'orderNo': this.$route.params.cardNo,
							'cardCode': this.$route.params.cardCode
						}
					});
					return;
				}
				this.$router.replace({
					"name": "order",
					query: {
						orderStatus: 1
					}
				});
			},
			//判断是否在可配送时间内
			getTimeRight() {
				console.log("去重新选择时间");
				return new Promise((resolve, reject) => {
					let url = window.api.trade_host + '/orderDeliveryPool/checkCanToPay/' + this.orderNo;
					var sessionId = localStorage.getItem('sessionId');
					let config = {
						url,
						method: 'GET',
						headers: {
							'sessionId': sessionId
						},
					};
					axios(config).then((res) => {
						// console.log(res.data.returncode,'返回参数');
						if(res.data.returnCode === 0) {
							resolve(false);
						} else if(res.data.returnCode === 1) {
							resolve(true);
						} else if(res.data.returnCode === 2) {
							Toast({
									message: res.data.msg,
									duration: 2000,
									type: 'warn'
								});
							this.$router.replace({
						        "name": "home"
					        });	
							/*this.$router.push({
								path: 'home',
							})*/
						}
					}).catch(err => {
						reject();
					});
				});

			},
			//定义处理异常错误的加工厂
			defaultErrorResolve() {
				return {
					//如果没有订单编号，默认跳转到个人中心
					orderNoError() {
						this.$router.replace({
							name: "profile"
						});
					}
				}
			},
			//处理成功后的跳转逻辑
			handlePaySuccessfully() {
				this.$store.commit('xxy/setPay', false)
				return {
					goResultPage: () => {
						//console.log('22222222222',this.orderType,orderTypeCode.lipinquan)
						// console.log("this.orderType", this.orderType)
						// console.log("this.orderType === 12", this.orderType === 12)
						if(this.orderType === orderTypeCode.lipinquan) {
							//跳转回礼品卡页面
							// console.log("这里要跳转回礼品卡页面");
							this.$router.replace({
								name: "GiftBuySuccess",
								query: {
									'orderType': this.orderType,
									'orderNo': this.$route.params.cardNo,
									'cardCode': this.$route.params.cardCode
								}
							});
						} else if(this.orderType === orderTypeCode.saomagou) {
							//核销页面
							// console.log("这里要跳转回核销页面");
							this.$router.replace({
								name: "scanOrder",
								query: {
									scanOrder: this.orderNo
								}
							
							});
						} else {
							this.$router.replace({
								name: "paysuccessfully",
								params: {
									orderType: this.orderType,
									orderNo: this.orderNo
								}
							});
						}
					}
				}
			},
			//初始化支付插件
			initPayPlugin() {
				let SEPayPlugin_Start = () => {
					//初始化
					cordova.require('cordova/channel').onCordovaReady.subscribe(function() {
						//  在安卓 进入后 在注册这个方法的时候 和安卓那边就已经调用这个方法了；
						//alert("start to pay 2, exec SEPayPlugin  ");
						cordova.exec(null, null, 'SEPayPlugin', null, []);
						//CenterCommandPlugin('start');
						doPay();
					});
				}
				let SEPayPlugin = (params, sucFunc, failFunc, opts, className) => {
					var params = params || null;
					var sucFunc = sucFunc || function() {};
					var failFunc = failFunc || function() {};
					var opts = opts || {};
					var className = className || null;
					try {
						console.log("11111111");
						cordova.exec(sucFunc, failFunc, "SEPayPlugin", this.phoneType === "Android" ? "doPay" : "start", [className, params, opts]);
					} catch(err) {
						alert("如您在app中进行支付，程序调起支付app失败，请点击按钮手动尝试下！")
					}
				}
				let doPay = () => {
					let data = {
						pay_no: this.payParams.pay_no,
						created_ts: this.payParams.created_ts,
						se_sign: this.payParams.se_sign,
						use_json: '0',
						order_money: this.payParams.amount
					}
					var pay = "sePay" + JSON.stringify(data);				
					//配置支付后的回调
					SEPayPlugin(pay,
						() => {
							console.log("支付回调", "支付成功");
							this.handlePaySuccessfully().goResultPage();
							// this.$router.replace({"name": "paysuccessfully", params: {orderType: this.orderType}});
						},
						() => {
							console.log("支付失败");
							Toast({
								message: '支付取消',
								type: "warn",
								duration: 1000
							});
						}
					);
				}

				return SEPayPlugin_Start;
			},
			//完全用钱包支付通知后台去做相应处理 
			walletNotice() {
				return new Promise((resolve, reject) => {
					let opt = {
						url: window.api.trade_host + api.WALLET_NOTICE + `/${this.orderNo}`,
						method: "post",
						headers: {
							sessionId: localStorage.getItem("sessionId")
						}
					}

					axios(opt).then(data => {
						// console.log(data);
						if(data.status === 200 && data.data.returnCode === 1) {
							resolve(true);
						} else {
							// console.log("钱包支付失败");
							resolve(false);
						}
					}).catch(err => {
						console.log(err);
						resolve(false);
					});
				});
			},
			//禁用支付点击事件
			disablePayClick() {
				this.isPaying = true;
				this.enablePayClick(1000);
			},
			//开启支付点击事件
			enablePayClick(time = 0) {
				setTimeout(() => {
					this.isPaying = false;
				}, time)
			},
			// 支付取消按钮置灰
			payCancel () {
				console.log('支付取消按钮置灰1')
				this.isPaying = false;
			},
			//初始化购买普通的后续
			async init2() {
				//处理异常错误
				if(!this.orderNo) {
					this.defaultErrorResolve()[orderNoError];
					return;
				}
				//支付按钮点击事件
				this.payClick = async() => {
					//如果已经在支付中，该事件直接结束掉（不能重复点击）
					if(this.isPaying) {
						console.log("正在支付中");
						return;
					}
					//设置正在支付中
					this.disablePayClick();
					//判断小周的方法，是否需要重新选择下单时间
					let handleMoneySituationState = await this.handleMoneySituation();
					// console.log("handleMoneySituationState", handleMoneySituationState)
					//如果handleMoneySituationState为false，这是一个短路操作，不会重新去选择时间
					//订单金额为0的不会重新选择时间
					let timeState = handleMoneySituationState && await this.getTimeRight();
					// console.log("timeState", timeState);
					if(!timeState && handleMoneySituationState) {
						//重新去选择时间
						this.$router.push({
							name: 'changeOrderTime',
							query: {
								orderNo: this.orderNo
							}
						});
						return;
					}
					//如果handleMoneySituationState为false，代表订单金额为0，直接跳转到支付成功页面
					//这种情况一般是使用了优惠券，抵扣订单金额为0
					//并结束掉操作
					if(!handleMoneySituationState) {
						//直接跳转到支付成功页面
						this.handlePaySuccessfully().goResultPage();
						return;
					}
					//获取当前支付方式、支付前置状态以及支付前置信息
					let beforePayInfo = this.judgePayWay(); //拿到一个对象
					console.log("支付方式：" + beforePayInfo.way);
					if(!beforePayInfo.state) {
						//支付前置状态不成功
						this.mToastFn(beforePayInfo.msg);
						return;
					}
					//根据支付前置信息判断是钱包支付
					if(beforePayInfo.way === way.wallet) {
						//判断有无设置过密码
						if(!this.passwordIsSet()) {
							this.$router.push({
								name: "SetKeyWallet",
								params: {
									goBack: true
								}
							});
							return;
						}
						//判断是否在免密范围内
						if(!this.judgeFreePassword()) {
							//开始调用密码盘输入密码
							this.$refs.passwardPanel.showOrHide();
							console.log("正在等待密码校验");
							await this.waitPasswordInputAndReg();
							console.log("等待密码校验完毕");
						}
						//先调用payNo接口
						await this.initPayParams(this.orderNo);
						//再调用钱包支付接口
						let data = await walletPay(this.orderNo);
						if(data.status === 200 && data.data.returnCode === 1) {
							//钱包支付成功
							this.$store.commit('xxy/setPay', false)
							this.handlePaySuccessfully().goResultPage();
						} else {
							//提示钱包支付不成功
							this.mToastFn("钱包支付失败");
						}
						return;
					}
					//请求翌支付的参数
					await this.initPayParams(this.orderNo);
					//初始化支付插件
					let SEPayPlugin_Start = this.initPayPlugin();
					//开始支付
					SEPayPlugin_Start();
				}
			},
			//初始化翌支付的参数
			initPayParams(params) {
				//一个公共方法
				let getParams = (listData) => {
					var pay_no = listData.pay_no;
					var app_code = listData.app_code;
					var se_payment_code = listData.se_payment_code;
					var se_private_key = listData.se_private_key;
					var created_ts = Date.parse(new Date()) / 1000; //
					var amount = listData.amount;
					var appStr = app_code + se_payment_code + pay_no + created_ts;
					var semd5 = md5(appStr) + se_private_key;
					var se_sign = md5(semd5);
					return {
						pay_no,
						created_ts,
						se_sign,
						amount
					}
				}
				//如果params是一个对象则使用这个参数初始化

				if(typeof params === "object") {
					return new Promise((resolve, reject) => {
						let p = getParams(params);
						this.payParams = {
							pay_no: p.pay_no,
							created_ts: p.created_ts,
							se_sign: p.se_sign,
							amount: p.amount
						}
						console.log("this.payParams", this.payParams);
						resolve();
					});
				}
				console.log("这不是购买礼品卡");
				//如果是一个字符串，则params是一个订单号，需要去请求数据来初始化参数
				return new Promise((resolve, reject) => {
					let options = {
						method: "post",
						url: window.api.trade_host + api.gwPay,
						data: {
							sessionId: localStorage.getItem("sessionId"),
							bill_id: params,
							scenary_id: "3",
							walletMoney: parseFloat(this.walletMoney), //当前用户选择的钱包支付金额
							thirdPartyMoney: parseFloat(this.thirdPayMoney), //当前用户选择的翌支付金额
						}
					}
					axios(options).then(data => {
						console.log("请求支付用的参数", data);
						if(data.status === 200) {
							if(data.data.data[0].returnCode != undefined) {
								resolve();
								return;
							}
							//给翌支付所需的参数赋值
							let result = getParams(data.data.data[0]);
							this.payParams = {
								pay_no: result.pay_no,
								created_ts: result.created_ts,
								se_sign: result.se_sign,
								amount: result.amount
							}
							resolve(result);
						} else {
							reject();
						}
					}).catch(err => {
						console.log(err);
						reject();
					});
				});
			},
			//初始化购买礼品卡的后续
			async init3() {
				//处理异常错误
				if(!this.orderNo) {
					this.defaultErrorResolve()[orderNoError];
					return;
				}
				// this.thirdPayMoney = this.totalMoney;
				this.payClick = async() => {
					//获取当前支付方式、支付前置状态以及支付前置信息
					let beforePayInfo = this.judgePayWay(); //拿到一个对象
					console.log("支付方式：" + beforePayInfo.way);
					if(!beforePayInfo.state) {
						//支付前置状态不成功
						this.mToastFn(beforePayInfo.msg);
						return;
					}
					//请求翌支付的参数
					await this.initPayParams(this.orderNo);
					//初始化支付插件
					let SEPayPlugin_Start = this.initPayPlugin();
					//开始支付
					SEPayPlugin_Start();
				}
			},
			//根据不同的金额类型判断不同的处理情况
			handleMoneySituation() {
				return new Promise((resolve, reject) => {
					//订单金额为0不用再去选择时间
					//目前只有使用优惠券全部抵扣的情况下，订单金额才为0
					if(parseFloat(this.totalMoney) > 0) {
						resolve(true);
					} else if(parseFloat(this.totalMoney) === 0) {
						resolve(false);
					}
				})
			},
			//初始化钱包余额
			initWalletBalance() {
				return new Promise(async(resolve, reject) => {
					let data = await getWalletBalance();
					// console.log("这是钱包余额", data);
					if(ValidatorFn(data)) {
						//返回值合法
						// this.walletBalance = 
						// console.log("这是钱包余额", data);
						this.walletBalance = (data.data.data[0].availAmount).toFixed(2);
					}
				});
			},
			//初始化页面数据（包含订单金额以及钱包余额）
			async initData() {
				//获取订单金额
				let orderInfo = this.orderType === 12 ? {
					totalPay: parseFloat(this.orderNo.amount),
					remainingTm: this.orderNo.autoCancel
				} : await getOrderInfo(this.orderNo);
				// let orderInfo = await getOrderInfo(this.orderNo);
				// 过期时间
				this.autoCancelTm = orderInfo.remainingTm
				//订单总额赋值
				this.totalMoney = (orderInfo.totalPay).toFixed(2);
				//获取钱包余额
				let walletBalanceData = await getWalletBalance();
				//钱包余额赋值
				this.walletBalance = (walletBalanceData.data.data[0].availAmount).toFixed(2);
				//初始换各支付方式选中情况和金额信息
				this.initPayWayState();
				//thirdPayMoney，第三方支付的金额=订单金额-钱包支付金额
				this.thirdPayMoney = (parseFloat(this.totalMoney) - parseFloat(this.walletMoney)).toFixed(2);
				if(this.orderType === 12) {
					//初始化购买礼品卡后续
					this.init3();
				} else {
					//初始化普通支付后续
					this.init2();
				}
			},
			//初始换各支付方式选中情况和金额信息
			initPayWayState() {
				//如果钱包余额大于等于订单总额，默认选中钱包支付，并把订单金额赋值给walletMoney，给子组件显示
				// if (walletBalanceData.data.data[0].availAmount >= orderInfo.totalPay) {
				if(this.orderType !== 12) {
					//初始化普通状态
					if(parseFloat(this.walletBalance) >= parseFloat(this.totalMoney)) {
						this.$store.commit("gw/setPayWay", [way.wallet]);
						this.walletMoney = this.totalMoney;
						this.fullWalletPay = true;
						console.log("this.fullWalletPay", this.fullWalletPay)
					}
					//如果钱包余额小于订单总额且不为0，默认选中钱包支付和翌支付，
					//并把钱包余额赋值给walletMoney，给子组件显示
					if(parseFloat(this.walletBalance) < parseFloat(this.totalMoney) && parseFloat(this.walletBalance) > 0) {
						this.$store.commit("gw/setPayWay", [way.wallet, way.yizhifu]);
						this.walletMoney = this.walletBalance;
					}
					//如果钱包余额为0，默认勾选中翌支付
					if(parseFloat(this.walletBalance) === 0) {
						this.$store.commit("gw/setPayWay", [way.yizhifu]);
						this.walletMoney = 0;
					}
				} else {
					//初始化礼品卡状态
					this.walletMoney = 0;
					this.$store.commit("gw/setPayWay", [way.yizhifu]);
				}
			},
			//判断各种支付方式相加是否合法，返回一个对象
			//{state: true, msg: "", way: ""}
			judgePayWay() {
				//已经对钱包金额大于订单金额做了校验
				//如果两者都没选中
				if(!this.walletChoosed && !this.yizhifuChoosed) {
					return {
						state: false,
						msg: "请选择支付方式",
						way: ""
					}
				}
				//如果钱包支付金额=订单总金额，则为钱包全额支付
				if(parseFloat(this.walletMoney) === parseFloat(this.totalMoney)) {
					console.log("钱包全额支付");
					return {
						state: true,
						msg: "使用钱包全额支付",
						way: way.wallet
					}
				}
				//如果钱包余额为0，则只能选择用翌支付进行支付
				if(parseFloat(this.walletBalance) === 0) {
					return {
						state: true,
						msg: "使用翌支付全额支付",
						way: way.yizhifu
					}
				}
				//如果钱包余额大于0，并且选择用了钱包支付和翌支付，但是不是全额
				if(parseFloat(this.walletMoney) < parseFloat(this.totalMoney) && this.yizhifuChoosed) {
					return {
						state: true,
						msg: "使用混合支付",
						way: way.mixins
					}
				}
				//支付金额不够
				if(parseFloat(this.walletMoney) < parseFloat(this.totalMoney) && !this.yizhifuChoosed) {
					return {
						state: false,
						msg: "请选择足够的金额进行支付",
						way: ""
					}
				}
			},
			//子组件在改变钱包支付金额的时候，触发的回调函数
			changeWalletMoneyEvent(val) {
				// console.log("改变钱包金额", val);
				this.walletMoney = val;
				// if (this.yizhifuChoosed) {
				if(val === "") {
					this.thirdPayMoney = this.totalMoney;
				} else {
					this.thirdPayMoney = (parseFloat(this.totalMoney) - parseFloat(this.walletMoney)).toFixed(2);
				}
				// }

			},
			//判断是否在免密范围内
			judgeFreePassword() {
				// return false;
				// console.log("this.moneyWithoutCode", this.moneyWithoutCode);
				// console.log("parseFloat(this.moneyWithoutCode)", parseFloat(this.moneyWithoutCode));
				// console.log("parseFloat(this.walletMoney)", parseFloat(this.walletMoney));
				// console.log("parseFloat(this.moneyWithoutCode) >= parseFloat(this.walletMoney)", parseFloat(this.moneyWithoutCode) >= parseFloat(this.walletMoney));
				// console.log(!this.moneyWithoutCode || parseFloat(this.moneyWithoutCode) >= parseFloat(this.walletMoney));
				//如果免密金额大于等于当前当前钱包支付金额，则不用输密码
				if(!this.moneyWithoutCode || parseFloat(this.moneyWithoutCode) >= parseFloat(this.walletMoney)) {
					return true;
				}
			},
			//判断是否设置过密码
			passwordIsSet() {
				// return false;
				//1为设置过密码
				return this.userInfo.walletStatus === "1";
			},
			//等待密码校验的promise
			waitPasswordInputAndReg() {
				return new Promise((resolve, reject) => {
					this.timer = setInterval(() => {
						//密码错误不会结束pending状态
						//忘记密码就要结束pending状态
						//resultCode: 2, 忘记密码
						// 一旦密码校验状态结束
						if(!this.pwPendingResult.pwPendingState) {
							// if(this.pwPendingResult.resultCode === 2) {
							// 	clearInterval(this.timer);
							// 	this.timer = null;
							// 	resolve(this.pwPendingResult);
							// 	return;
							// }
							if (this.pwPendingResult.result) {
								clearInterval(this.timer);
								this.timer = null;
								//重新置为初始状态，等待用户下一次输入
								resolve(this.pwPendingResult);
							} else {
								//密码校验失败
								this.mToastFn(this.pwPendingResult.msg);
							}
							this.pwPendingResult.pwPendingState = true;
						} 
					}, 100);
				});
			},
			mToastFn(msg, duration = 1000, type = "fail") {
				Toast({
					message: msg,
					type,
					duration
				});
			},
			//当输入密码组件校验完毕后改变pending值
			passwordPendingChangeEvent(obj) {
				//接收到一个对象
				this.pwPendingResult = obj;
			},
			//在vuex中置一个标志位为true，用来监控原生back键的返回
			setNativeBackFlagForPayIsTrue() {
				this.$store.commit("setNativeBackFlagForPay", true);
			},
			//获取APP版本号
			//不在象谱APP内，默认返回100.100.100
			getAppVersion() {
				let plugin = this.phoneType === "Android" ? "AppInfo" : "CommonPlugin";
				let method = this.phoneType === "Android" ? "getVersion" : "getAppVersion";
				return new Promise(resolve => {
					if (!this.isXiangpu) {
						resolve("100.100.100");
						// resolve("1.2.3");
						return;
					}
					cordova.exec(res => {
						// console.log("获取到APP的版本号", res);
						resolve(res);
					}, () => {
						console.log("获取APP版本号失败");
						resolve("100.100.100");
					}, plugin, method, []);
				});
			},
			//判断APP版本号，只有当Android版本小于1.2.5的时候才会进入老的支付流程
			async judgeAppVersionisHigher() {
				let androidPayHigherVersion = parseInt(window.api.android_pay_version);
				let iosPayHigherVersion = parseInt(window.api.ios_pay_version);
				console.log("androidPayHigherVersion", androidPayHigherVersion);
				console.log("iosPayHigherVersion", iosPayHigherVersion);
				let version = await this.getAppVersion();
				let versionNumber = Number(version.split(".").join(""));
				console.log("拿到的版本号-judgeAppVersionisHigher", version, versionNumber);
				// console.log(this.phoneType === "Android" && versionNumber >= 125);
				// console.log(this.phoneType === "Android");
				// console.log(versionNumber >= 125);
				if (this.phoneType === "Android" && versionNumber >= androidPayHigherVersion) {
					return true;
				}
				if (this.phoneType === "iOS" && versionNumber >= iosPayHigherVersion) {
					return true;
				}
				return false;
			}
			
		},
		components: {
			"m-pay": Pay,
			"passward-panel": passwardPanel,
		},
		watch: {
			//监听子组件中操作支付方式
			getPayWay(newVal) {
				// console.log("支付方式发生改变", newVal);
				//当钱包支付方式取消掉并且翌支付是勾选状态，自动把翌支付的金额变为订单金额
				if(!this.walletChoosed && this.yizhifuChoosed) {
					// console.log("勾选掉了钱包支付", this.totalMoney);
					this.thirdPayMoney = this.totalMoney;
					this.walletMoney = "0.00";
				} else if(this.walletChoosed && !this.yizhifuChoosed) {
					//如果钱包勾选并且翌支付没有勾选，则需要判断钱包可用金额是否大于等于订单金额
					//如果是，则将订单金额赋给钱包金额，
					//否则将可用金额赋给钱包金额
					this.walletMoney = parseFloat(this.walletBalance) >= parseFloat(this.totalMoney) ?
						this.totalMoney : this.walletBalance;
					//勾选上了钱包支付
				} else if(this.walletChoosed && this.yizhifuChoosed) {
					//两者都勾选，则翌支付金额为订单总金额减去钱包支付金额
					this.thirdPayMoney = (parseFloat(this.totalMoney) - parseFloat(this.walletMoney)).toFixed(2);
				}
			}
		},	
		async created() {
			//判断当前app版本号
			// this.$router.replace({name: "otherPay", params: {
			// 	orderNo: this.orderNo,
			// 	orderType: this.orderType
			// }});
			// return;
			// let flag = await this.judgeAppVersionisHigher();
			// console.log("是否启用新的支付流程", flag);
			// if (flag) {
			// 	this.$router.replace({name: "newPay", params: {
			// 		orderNo: this.orderNo,
			// 		orderType: this.orderType
			// 	}});
			// } else {
				this.initData();
			// }
			// this.setNativeBackFlagForPayIsTrue();
			// console.log("this.orderNo", this.orderNo);
		},
		beforeCreate () {
			console.log(this.$route.params.orderType,'999')
			this.$store.commit('xxy/setPay', true)
		},
		async beforeRouteLeave(toRoute, fromRoute, next) {
			//取消定时器
			this.$store.commit('xxy/setPay', false)
			next()
		}

	}
</script>

<style>

</style>